package com.yoomiito.app.ui.fragment.my;

import android.os.Bundle;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.yoomiito.app.Constant;
import com.yoomiito.app.adapter.my.MyOrderAdapter;
import com.yoomiito.app.model.my.MyOrderBean;
import com.yoomiito.app.model.my.MyVipBean;
import com.yoomiito.app.present.my.fragment.MyVipFmPresenter;

import java.util.ArrayList;
import java.util.List;

import cn.droidlover.xdroidmvp.net.ApiException;

/**
 * 我的---礼品/爆品/优品
 */
public class MyVipFragment extends MyOrderBaseFragment<MyVipFmPresenter> {

    public static final String MyVipFm = "MyVipFm";

//    @BindView(R.id.rv_order)
//    RecyclerView mRecyclerView;
    private MyOrderAdapter mAdapter;
    private List<MyOrderBean> mList;
    public final static String KEY_TYPE = "key_type";
    private int type;

    @Override
    public MyVipFmPresenter newP() {
        return new MyVipFmPresenter();
    }

    @Override
    public void initData(Bundle savedInstanceState) {
        super.initData(savedInstanceState);
        if (getArguments() != null) {
            type = getArguments().getInt(KEY_TYPE, Constant.VIP_TYPE_GIFT);
        }
        mList = new ArrayList<>();
        mAdapter = new MyOrderAdapter(mList, MyOrderAdapter.ORDER_TYPE_VIP, MyVipFm);
        mRecyclerView.setAdapter(mAdapter);

        getNewData();
    }

    @Override
    protected void getNewData() {
        getP().getUserCenterData(currentPage, type);
    }

    @Override
    public String getEmptyContent() {
        return "未购买商品";
    }

    @Override
    public void handleError(ApiException e) {

    }

    public void setData(MyVipBean data) {
        if (currentPage == 1) {
            if (data != null && data.getData() != null&&data.getData().size()>0) {
                mAdapter.setNewData(data.getData());
                mSmartRefreshLayout.finishRefresh(true);
                mStatusManager.showContent();
//                ((MyVipOrderActivity) context).setTabNum(
////                        data.getLibaoSum(),
////                        data.getBaopinSum(),
////                        data.getFineSum()
//                        "1000000",
//                        "100000",
//                        "10000"
//                );
            }else {
                mStatusManager.showEmpty();
            }
        } else {
            mSmartRefreshLayout.finishLoadMore(true);
            if (data.getData() == null || data.getData().size() == 0) {
                mSmartRefreshLayout.finishLoadMoreWithNoMoreData();
            } else {
                mAdapter.addData(data.getData());
            }
        }
    }
}
